package demo1;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 28779
 * Date: 2023-04-03
 * Time: 8:20
 */
class MyArray<T>{
    public T[] objects = (T[]) new Object[10];

    public T getpos(int pos){
        return this.objects[pos];
    }
    public void setVal(int pos, T val) {
        objects[pos] = val;
    }
}
/*class MyArray{
    public Object[] objects = new Object[10];

    public Object getpos(int pos){
        return this.objects[pos];
    }
    public void setVal(int pos, Object val) {
        objects[pos] = val;
    }
}*/

public class Test {
    public static void main(String[] args) {
        MyArray<String> myArray = new MyArray<String>();  //后面的String可以省略
        myArray.setVal(0,"张兆涵");
        String ret = myArray.getpos(0);
        System.out.println(ret);
    }

    public static void main1(String[] args) {
        MyArray myArray = new MyArray();
        myArray.setVal(0,"张兆涵");
        String ret = (String) myArray.getpos(0);
        System.out.println(ret);
    }
}
